package com.example.xm.utils;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.HashMap;

public class JWTUtils {
    private static final String KEY="ttttttt";
    private static final Long EXPIRED_DATE=30L*24*60;
    public static String getToken(  HashMap<String, Object> map){
        Date date = new Date(System.currentTimeMillis() + EXPIRED_DATE*60*1000);
        String token = Jwts.builder().setHeaderParam("typ","jwt").setHeaderParam("alg","HS256")
                .setClaims(map).setExpiration(date).signWith(SignatureAlgorithm.HS256,KEY)
                .compact();
        return token;
    };
    public static Claims parse(String jwt){
        Claims body = Jwts.parser().setSigningKey(KEY).parseClaimsJws(jwt).getBody();
        return body;
    }
}
